//
//  NetDownloadBooks.h
//  KidReading
//
//  Created by telen on 14/12/11.
//  Copyright (c) 2014年 刘赞黄Telen. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "JRASIHTTPRequest.h"

#define __DownBooksInfo__ @"DownBooksInfo"

//这个协议做下载处理，返回未加工数据
//down中，已经直接对zip数据解压
#pragma mark- NetDownloadBooksDelegate
@protocol NetDownloadBooksDelegate <NSObject>
@optional
//常规下载回执
- (void)netDownloadBookOneZipFinished:(NSDictionary*)dict;
- (void)netDownloadBookOneZipFailed:(NSDictionary*)dict;
- (void)netDownloadBooksPercentage:(CGFloat)per bookID:(NSInteger)bookid;
@end

//通知协议，回执下载和解压后的状态数据
@protocol NetDownloadBooksNotice <NSObject>

@optional
//注册通知反馈
- (void)netNotice_DownloadBooksPercentage:(CGFloat)per bookID:(NSInteger)bookid;
- (void)netNotice_DownloadBooksAllFinished:(NSInteger)bookid;
- (void)netNotice_DownloadBooksAllFinished:(NSInteger)bookid throughDict:(NSDictionary*)throughDict;
- (void)netNotice_DownloadBooksAllEndHasFailed:(NSInteger)bookid;
- (void)netNotice_DownloadBookFinishedOneZipIndex:(NSInteger)zipIndex bookID:(NSInteger)bookid;
- (void)netNotice_DownloadBookFinishedOneZipIndex:(NSInteger)zipIndex bookID:(NSInteger)bookid throughDict:(NSDictionary*)throughDict;
//
- (void)netNotice_CancelDownloadBook:(NSInteger)bookid;
- (void)netNotice_ReadyDownloadBook:(NSInteger)bookid;

@end

@interface zipDownInfo : NSObject
@property(nonatomic,assign)NSInteger relZipIndex; //包的真实顺序 索引
@property(nonatomic,assign)NSInteger zipIndex;//zip包的编号，顺序安装server提供的数组
@property(nonatomic,copy)NSString* zipPath;//zip包的存储路径
@property(nonatomic,assign)long long zipSize;//从server的请求头里获得的zip下载大小
@property(nonatomic,assign)float zipDownPercentage;//zip包的下载进度
@end

@interface BookDownInfo : NSObject
{
    float percentage;
}
@property(nonatomic,assign)NSInteger bookid;
@property(nonatomic,assign)long long bookEdition;
@property(nonatomic,strong)NSDictionary *listInfo;//每个链接的版本信息
@property(nonatomic,assign)NSInteger zipCount;
@property(nonatomic,strong)NSMutableString *zipsStatus;//按字符串方式从第一位开始记录每个包的下载状态，1为成功
@property(nonatomic,assign)NSInteger countDownSuccess;//下载并解压成功的zip包个数
@property(nonatomic,assign)NSInteger countDownFailed;
- (void)addpercentage:(float)per;//快速更新整书百分比
- (float)getPer;//返回整个书本多个zip包合计的下载进度n
@end

#pragma mark- NetDownloadBooks
@interface NetDownloadBooks : NSObject<JRASIHTTPRequestDelegate,JRASIProgressDelegate>
{
    NSMutableArray* noticeDelegateArr;
    //
    NSMutableArray* downingBooksInfoArr;
    //
    NSMutableArray* downQueue;
    NSMutableArray* downIngQueue;
    int que_maxConcurrentOperationCount;
    //
    NSMutableArray* downBookQueueAllNet;
}

+ (NetDownloadBooks*)shareSingle;

- (void)downBooksUrl:(NSArray*)urlStrArr delegate:(id<NetDownloadBooksDelegate>)delegate withBookID:(NSInteger)bookid edition:(long long)edition withThroughDict:(NSDictionary*)throughDict allNetType:(BOOL)allnet;

- (void)downBooksUrl:(NSArray*)urlStrArr delegate:(id<NetDownloadBooksDelegate>)delegate withBookID:(NSInteger)bookid edition:(long long)edition withThroughDict:(NSDictionary*)throughDict;

//
- (void)addDownQueueAllNet:(NSInteger)bookid;
- (void)downBooksUrl:(NSArray*)urlStrArr relIndex:(NSArray*)numArr delegate:(id<NetDownloadBooksDelegate>)delegate withBookID:(NSInteger)bookid edition:(long long)edition withThroughDict:(NSDictionary*)throughDict;
//

- (void)cancelDownBooks:(NSInteger)bookid;
- (void)cancelDownBooksAll;
- (NSArray*)getAllWaitingDownBooks;
- (BOOL)isBookDownWaiting:(NSInteger)bookid;
- (BOOL)isBookDowning:(NSInteger)bookid;
- (CGFloat)getBookDowningPer:(NSInteger)bookid;

- (NSString *)getDownStatusForBook:(NSInteger)bookid;
//
- (void)queDown:(JRASIHTTPRequest*)request;
- (void)downSuccessOpreationWithBookDownInfo:(BookDownInfo *)bookdowninfo;

//注册通知反馈
- (void)registerDownBooksStatusNotice:(id<NetDownloadBooksNotice>)delegate;
- (void)unRegisterDownBooksStatusNotice:(id<NetDownloadBooksNotice>)delegate;

@end
